import java.util.InputMismatchException;
import java.util.Scanner;


public class Test {

    public static void main(String[] args) {
//        Scanner scanner = new Scanner(System.in);
//        try{
//            int n = scanner.nextInt();
//        }catch (InputMismatchException e){
//            e.printStackTrace();
//            System.out.println("输入类型不匹配");
//        }finally {
//            System.out.println("执行了finally");
//            scanner.close();
//        }
        try (Scanner scanner = new Scanner(System.in)) {
            int n = scanner.nextInt();
        } catch (InputMismatchException e) {
            e.printStackTrace();
            System.out.println("输入类型不匹配");
        } finally {
            System.out.println("执行了finally");
        }
    }

    public static void test1(int a){
        if(a == 10){
            throw new NullPointerException();
        }
    }

    public static void test3(int c){
//        if(c == 10){
//            throw new CloneNotSupportedException();
//        }
        //受查时异常
        //处理方法
        //法一
        try{
            throw new CloneNotSupportedException();
        }catch(CloneNotSupportedException e){
            e.printStackTrace();
        }
        //法二
        //在方法后 throws Exception
        //并在main中用try_catch
    }
    public static void test2(int b){
        try{
            if(b == 10){
                throw new NullPointerException();
            }
        }catch (NullPointerException e){
            e.printStackTrace();
        }
        System.out.println("test2执行");
    }

    public static void main3(String[] args) {
        test2(10);
        System.out.println("main执行");
    }

    public static void main2(String[] args) {
        try{
            test1(10);
        }catch (NullPointerException e){
            e.printStackTrace();
        }
        System.out.println("后续操作");

    }

    public static void main1(String[] args) {
        //编译过程程序自动抛出异常
        try{
            //System.out.println(10/0);
            int[] array = {1,2,3,4};
            array = null;
            System.out.println(array[0]);
        }catch (ArithmeticException e){
            e.printStackTrace();//打印出异常信息
            System.out.println("出现算数异常");
        }catch (NullPointerException e){
            e.printStackTrace();
            System.out.println("捕捉到了空指针异常");
        }catch (ArrayIndexOutOfBoundsException e){
            e.printStackTrace();
            System.out.println("数组越界异常");
        }catch (Exception e){//把父类放到最后
            e.printStackTrace();
            System.out.println("出现异常");
        }
        System.out.println("执行后续代码");
        //catch(Exception e) - 直接检测所有异常
        //catch(Ari...ion | Null...ion) - 将几种异常放到一块
        //不便于弄清一场种类，不建议
    }
}
